/**
1,画线的，从一个mc到另个mc,不管这2个mc是在什么层级结构
这个也是有局限的,线是要在全局的
注意分析问题，
*/
package kgame5.kgui.kcomp {
import kgame5.kgui.GP;

import flash.display.*;
import flash.events.*;
import flash.geom.*;

public class SmartLine{
	
	//___________________PROPERTY___________________
	private var 
		mc_A:DisplayObject,
		mc_B:DisplayObject;
	
	private var 
		mc_line:MovieClip;// 这个是提前准备好的那条线
		
	private var color:int;
	//___________________METHOD______________________
	//注意mc_tip是放在最外层的，就是根部
	public function SmartLine(p_mc_A:DisplayObject,p_mc_B:DisplayObject,p_mc_line:MovieClip,p_color:int=0xff0000){
		mc_A=p_mc_A;
		mc_B=p_mc_B;
		
		mc_line=p_mc_line;
		
		
		mc_line.visible=false;
		
		color=p_color;
	}
	public function Start(){
		show();
		mc_line.addEventListener(Event.ENTER_FRAME, efh);
	}
	public function Clear(){
		hide();
		mc_line.removeEventListener(Event.ENTER_FRAME, efh);
	}
	
	public function show(){
		mc_line.visible=true;
	}
	public function hide(){
		mc_line.visible=false;
	}
	
	
	private function efh(e:Event){
		/*
		var p0:Point=mc_A.localToGlobal(new Point(0,0));
		var p1:Point=mc_B.localToGlobal(new Point(0,0));
		
		//var len:Number=MathDG.getDistance(p0.x, p0.y,0,p1.x,p1.y,0);
		//var angle:Number=MathDG.AAA(p0.x,p0.y,p1.x,p1.y);
		
		//mc_line.x=p0.x;
		//mc_line.y=p0.y;
		
		//mc_line.width=len;
		//mc_line.rotation=angle;
		mc_line.graphics.clear();
		
		GP.drawLine(mc_line.graphics, color, p0.x, p0.y, p1.x, p1.y);//画线
		//*/
		
		//---两个mc要中心线相连接
		var rect0:Rectangle=mc_A.getRect(mc_A.stage);
		var rect1:Rectangle=mc_B.getRect(mc_B.stage);
		
		var x0:Number=rect0.x + rect0.width/2;
		var y0:Number=rect0.y + rect0.height/2;
		
		var x1:Number=rect1.x + rect1.width/2;
		var y1:Number=rect1.y + rect1.height/2;
		
		//画线
		mc_line.graphics.clear();
		
		GP.drawLine(mc_line.graphics, color, x0, y0, x1, y1);
	}
}//end of class
}